﻿<pfui:VsDialogWindow 
    x:Class="NuGet.Dialog.SolutionExplorer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:self="clr-namespace:NuGet.Dialog.PackageManagerUI"
    xmlns:local="clr-namespace:NuGet.Dialog"
    xmlns:resources="clr-namespace:NuGet.Dialog"
    xmlns:pfui="clr-namespace:NuGet.VisualStudio;assembly=NuGet.VisualStudio"
    xmlns:vsfx="clr-namespace:NuGet.VisualStudio;assembly=NuGet.VisualStudio"
    ResizeMode="CanResize"
    MinWidth="350"
    MinHeight="300"
    Width="400"
    Height="400"
    ShowInTaskbar="False"
    WindowStyle="SingleBorderWindow"
    WindowStartupLocation="CenterOwner"
    Title="{x:Static resources:Resources.Dialog_ProjectSelectorTitle}"
    local:WindowSizePersistenceHelper.WindowToken="SolutionExplorer"
    AutomationProperties.AutomationId="ManagePackages_SelectProjectsDialog"
    Background="{DynamicResource {x:Static local:UIResources.WindowBackgroundBrushKey}}">
    
    <Window.Resources>        
        <self:ProjectToIconConverter x:Key="ProjectToIconConverter" />
        
        <Style TargetType="{x:Type Button}">
            <Setter Property="Margin" Value="10,10,0,0" />
            <Setter Property="MinWidth" Value="75" />
            <Setter Property="MinHeight" Value="23" />
            <Setter Property="Padding" Value="4,0" />
        </Style>
        
        <DataTemplate DataType="{x:Type local:ProjectNode}">
            <StackPanel Orientation="Horizontal" Margin="2,0">
                <CheckBox AutomationProperties.AutomationId="ProjectCheckBox" IsChecked="{Binding IsSelected}" VerticalAlignment="Center" Focusable="False" />
                <Image x:Name="FolderImage" Margin="2,0" Stretch="None" Source="{Binding Project, Converter={StaticResource ProjectToIconConverter}}" />
                <TextBlock Text="{Binding Name}" VerticalAlignment="Center" />
            </StackPanel>
        </DataTemplate>

        <HierarchicalDataTemplate DataType="{x:Type local:FolderNode}" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal" Margin="2,0">
                <CheckBox IsChecked="{Binding IsSelected}" VerticalAlignment="Center" Focusable="False" />
                <Image x:Name="FolderImage" Margin="2,0" Stretch="None" Source="{Binding Icon}" />
                <TextBlock Text="{Binding Name}" FontWeight="SemiBold" VerticalAlignment="Center" />
            </StackPanel>
        </HierarchicalDataTemplate>
    </Window.Resources>
    
    <DockPanel Margin="10,10,10,8">
        <TextBlock x:Name="InstructionText" DockPanel.Dock="Top" TextWrapping="Wrap" Margin="0,0,0,3" Foreground="{DynamicResource {x:Static vsfx:VsBrushes.WindowTextKey}}" />
        
        <UniformGrid DockPanel.Dock="Bottom" HorizontalAlignment="Right" Columns="2">
            <Button AutomationProperties.AutomationId="OkButton" Content="{x:Static resources:Resources.Dialog_OK}" IsDefault="True" Click="OnOKButtonClicked" />
            <Button AutomationProperties.AutomationId="CancelButton" Content="{x:Static resources:Resources.Dialog_Cancel}" IsCancel="True" Click="OnCancelButtonClicked" />
        </UniformGrid>

        <TreeView x:Name="SolutionTreeView"  AutomationProperties.AutomationId="SolutionTreeView" ItemsSource="{Binding ProjectNodes}" KeyUp="OnSolutionTreeViewKeyUp" >
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsEnabled" Value="{Binding IsEnabled, Mode=OneWay}" />
                    <Setter Property="Margin" Value="0,2,0,2" />
                </Style>
            </TreeView.ItemContainerStyle>
        </TreeView>
    </DockPanel>
</pfui:VsDialogWindow>